package org.jackysoft.struts2.core;

import java.util.Collection;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Namespace;
import org.jackysoft.entity.Department;
import org.jackysoft.entity.DepartmentType;
import org.jackysoft.entity.Role;
import org.jackysoft.entity.User;
import org.jackysoft.entity.WorkflowSettingPK;
import org.jackysoft.google.collection.ZTreeNode;
import org.jackysoft.service.ComponentService;
import org.jackysoft.struts2.UtilsCRUDAction;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;


@Controller
@Namespace("/business")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class ComponentAction extends UtilsCRUDAction<ZTreeNode> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6257090375441768221L;
	private ComponentService service;  
 	private Department bean;
	private WorkflowSettingPK settingId;
	private Role role;
	private User owner;	
	private Collection<DepartmentType> dtypes;	
	private Collection<ZTreeNode> beans;
	
	public String ztree() throws Exception{
		beans = service.getZTreeNodes(bean, role, settingId);
		return BEANLIST;			
	}
	
	public String ztreeall() throws Exception{
		beans = service.getZTreeNodes(bean);
		return BEANLIST;
	}
	
	public String roomonly() throws Exception{
		beans = service.getZTreeNodes(bean, dtypes);
		return BEANLIST;
	}

	public String removeuser() throws Exception {
		service.deleteUser(owner);
		return SUCCESS;
	}	

	public Department getBean() {
		return bean;
	}

	public void setBean(Department bean) {
		this.bean = bean;
	}

	public WorkflowSettingPK getSettingId() {
		return settingId;
	}

	public void setSettingId(WorkflowSettingPK settingId) {
		this.settingId = settingId;
	}

	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	@Resource
	public void setService(ComponentService businessService) {
		this.service = businessService;
	}

	public void setOwner(User owner) {
		this.owner = owner;
	}

	public User getOwner() {
		return owner;
	}	

	public Collection<ZTreeNode> getBeans() {
		return beans;
	}

	public void setBeans(Collection<ZTreeNode> beans) {
		this.beans = beans;
	}

	public Collection<DepartmentType> getDtypes() {
		return dtypes;
	}


	public void setDtypes( Collection<DepartmentType> dtypes) {
		this.dtypes = dtypes;
	}

}
